﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="purchaseWeekEdit.aspx.cs"
    Inherits="PeisongWeb.admin.buyerPriceWeekEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register TagName="top" Src="controls/top.ascx" TagPrefix="uc1" %>
<%@ Register TagName="menu" Src="controls/menu.ascx" TagPrefix="uc2" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>企业周报价表</title>
    <!--#include file="style.inc"-->
    <script src="/app_common/scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="/app_common/scripts/json-minified.js" type="text/javascript"></script>
    <script src="/app_common/scripts/QueryString.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="sm1" runat="server">
    </asp:ScriptManager>
    <ext:ScriptManager ID="ScriptManager1" runat="server" />
    <uc1:top ID="Top1" runat="server" />
    <uc2:menu ID="Menu1" runat="server" />
    <p>
        &nbsp;&nbsp;</p>
    <div id="admin_main" style="margin: 10px 0 0 10px;">
        <ext:Panel ID="panel_Title" runat="server" Title="企业周报价" BodyStyle="padding:5px 5px 0"
            Width="960" Frame="true" ButtonAlign="Center">
            <Body>
                <div id="admin_edit_content">
                    <ul>
                        <li>
                            <label>
                                企业名称</label>
                            <asp:Literal runat="server" ID="lblCompany"></asp:Literal>
                        </li>
                        <li>
                            <label>
                                周</label>
                            <asp:Literal runat="server" ID="lblWeek"></asp:Literal>
                        </li>
                        <li>
                            <label>
                                开始日期</label>
                            <asp:Literal runat="server" ID="lblStartTime"></asp:Literal>
                        </li>
                        <li>
                            <label>
                                结束日期</label>
                            <asp:Literal runat="server" ID="lblEndTime"></asp:Literal>
                        </li>
                        <li>
                            <label>
                                创建人</label>
                            <asp:Literal runat="server" ID="lblCreateAdmin"></asp:Literal>
                        </li>
                        <li>
                            <label>创建日期</label>
                            <asp:Literal runat="server" ID="lblCreateDt"></asp:Literal>
                        </li>
                        <li>
                            <label>
                                审核人</label>
                            <asp:Literal runat="server" ID="lblAuditAdmin"></asp:Literal>
                        </li>
                        <li>
                            <label>审核时间</label>
                            <asp:Literal runat="server" ID="lblAuditDt"></asp:Literal>
                        </li>
                    </ul>
                    <p>
                        <table width="98%" border="0" cellpadding="4" cellspacing="1">
                            <tr>
                                <td>
                                    <h2 style="float: left; margin-right: 20px">
                                        周报价商品</h2>
                                    <span>
                                        <asp:LinkButton runat="server" ID="lbn_AddProduct" Text="添加商品" OnCommand="lbn_AddProduct_Click"
                                            CausesValidation="false"></asp:LinkButton>
                                    </span>
                                    <span>&nbsp;&nbsp;</span>
                                    <span><del>
                                        <asp:LinkButton runat="server" ID="lbl_ExportToExcel" Text="导出Excel" ToolTip="导出企业周报价"
                                        CausesValidation="false" onclick="lbl_ExportToExcel_Click"></asp:LinkButton></del>
                                    </span>
                                    <hr />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div id="admin_edit_content_infor" style="width: 630px">
                                        <table width="98%" id="t11">
                                            <tr align="center" style="height: 20px;">
                                                <td bgcolor="#C0D5F0">
                                                    序号
                                                </td>
                                                <td bgcolor="#C0D5F0">
                                                    商品名称
                                                </td>
                                                <td bgcolor="#C0D5F0">
                                                    当前平均供应价
                                                </td>
                                                <td bgcolor="#C0D5F0">
                                                    系统加价比例
                                                </td>
                                                <td bgcolor="#C0D5F0">
                                                    价格
                                                </td>
                                                <td bgcolor="#C0D5F0">
                                                    删除
                                                </td>
                                            </tr>
                                            <asp:Repeater runat="server" ID="rptSelectedProduct" OnItemCommand="rptSelectedProduct_ItemCommand">
                                                <ItemTemplate>
                                                    <tr align="center" style="height: 20px;">
                                                        <td bgcolor="#FFFFFF">
                                                            <%#Container.ItemIndex+1 %>
                                                            <asp:HiddenField runat="server" ID="hdProductId" Value='<%#Eval("ProductId") %>' />
                                                        </td>
                                                        <td bgcolor="#FFFFFF">
                                                            <%#Eval("ProductName")%>
                                                        </td>
                                                        <td bgcolor="#FFFFFF">
                                                            <asp:Literal runat="server" ID="lblAvgSellerPrice" Text='<%#Eval("AvgSellerPrice") %>'></asp:Literal>
                                                        </td>
                                                        <td bgcolor="#FFFFFF">
                                                            <asp:TextBox runat="server" onblur="calc(this);" ID="txtAutoAdd" Text='<%#Eval("AutoAdd") %>' size="5"></asp:TextBox>
                                                            <asp:HiddenField runat="server" ID="hdAutoAdd" Value='<%#Eval("InitAutoAdd") %>' />
                                                        </td>
                                                        <td bgcolor='#FFFFFF'>
                                                            <asp:TextBox runat="server" ID="txtPrice" Text='<%#Eval("Price","{0:F2}")%>' Width="75px"></asp:TextBox>
                                                        </td>
                                                        <td bgcolor="#FFFFFF">
                                                            <asp:LinkButton runat="server" ID="link_SelectedProduct_Del" CausesValidation="false"
                                                                CommandArgument='<%#Eval("ProductId") %>' CommandName="Del" Text="删除"></asp:LinkButton>
                                                        </td>
                                                    </tr>
                                                </ItemTemplate>
                                            </asp:Repeater>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </p>
                    <p>&nbsp;&nbsp;</p>
                    <ul>
                        <li>
                            <label>&nbsp;</label>
                            <asp:Button runat="server" ID="btnSaveWeeklyPrice" Text="保存周价商品" 
                                onclick="btnSaveWeeklyPrice_Click" />
                            <asp:Button runat="server" ID="btnAudit" Text="审核通过" onclick="btnAudit_Click" />
                            <input type="button" onclick="javascript:window.close();" value="关闭返回" />
                        </li>
                    </ul>
                </div>
            </Body>
        </ext:Panel>
        <ext:Window ID="win_product" runat="server" Title="添加商品" Height="550px" Width="900px"
            BodyStyle="padding: 6px; background-color: #fff;" AutoScroll="true" Modal="True"
            Resizable="false" ShowOnLoad="false" Draggable="true" Icon="ApplicationViewDetail">
            <Body>
                <asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
                    <Triggers>
                        <asp:PostBackTrigger ControlID="lbn_AddTo" />
                    </Triggers>
                    <ContentTemplate>
                        <div class="details">
                            <table width="98%" border="0" cellpadding="4" cellspacing="1" style="text-align: left">
                                <tr>
                                    <td style="width: 18%;">
                                        <label style="line-height: 20px;">
                                            大 类：</label>
                                        <asp:DropDownList runat="server" ID="ddl_CategoryRoot" DataTextField="name" DataValueField="categoryId"
                                            AutoPostBack="True" OnSelectedIndexChanged="ddl_CategoryRoot_SelectedIndexChanged">
                                        </asp:DropDownList>
                                    </td>
                                    <td style="width: 18%">
                                        <label style="line-height: 20px;">
                                            小 类：</label>
                                        <asp:DropDownList runat="server" ID="ddl_CategorySub" DataTextField="name" DataValueField="categoryId">
                                        </asp:DropDownList>
                                    </td>
                                    <td style="width: 18%">
                                        商品编号:<asp:TextBox ID="txt_ProductNo" runat="server" Width="80px"></asp:TextBox>
                                    </td>
                                    <td style="width: 18%">
                                        商品名称:<asp:TextBox ID="txt_ProductName" runat="server" Width="80px"></asp:TextBox>
                                    </td>
                                    <td style="width: 16%">
                                        <asp:LinkButton ID="lbn_search" runat="server" Text="［搜索］" CausesValidation="false"
                                            OnClick="lbn_search_Click"></asp:LinkButton>
                                        <asp:LinkButton ID="lbn_reset" runat="server" Text="[重置]" CausesValidation="false"
                                            OnClick="lbn_reset_Click"></asp:LinkButton>
                                    </td>
                                    <td style="width: 16%">
                                        <asp:LinkButton ID="lbn_AddTo" runat="server" Text="[确认添加]" CausesValidation="false"
                                            OnClick="lbn_AddTo_Click" OnClientClick="return ValidateDuplicate();"></asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                            <table id="tb_pro" width="98%" border="0" cellpadding="4" cellspacing="1" bgcolor="#99BBE8"
                                style="text-align: left">
                                <asp:Repeater runat="server" ID="rpt_Products">
                                    <HeaderTemplate>
                                        <tr align="center" style="height: 20px;">
                                            <td width="10%" bgcolor="#C0D5F0">
                                                商品编号
                                            </td>
                                            <td width="30%" bgcolor="#C0D5F0">
                                                商品名称
                                            </td>
                                            <td width="20%" bgcolor="#C0D5F0">
                                                周平均供应价
                                            </td>
                                            <td width="10%" bgcolor="#C0D5F0">
                                                加价比例
                                            </td>
                                            <td width="30%" bgcolor="#C0D5F0">
                                                <input type="checkbox" name="checkedAll" id="checkedAll" onclick="selectAll(this);" />全选/取消
                                            </td>
                                        </tr>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <tr align="center" style="height: 20px;">
                                            <td bgcolor="#FFFFFF">
                                                <%# Eval("productNo")%>
                                            </td>
                                            <td bgcolor="#FFFFFF">
                                                <%# Eval("name")%>
                                            </td>
                                            <td bgcolor="#FFFFFF">
                                                <%#Eval("avgSellerPrice","{0:F2}") %>
                                            </td>
                                            <td bgcolor="#FFFFFF">
                                                <%#Eval("autoAdd","{0:F2}") %>
                                            </td>
                                            <td bgcolor="#FFFFFF" align="center">
                                                <asp:CheckBox ID="cbx_isSelect" ProductId='<%#Eval("productId") %>' ProductName='<%#Eval("name") %>' AvgSellerPrice='<%#Eval("avgSellerPrice") %>' AutoAdd='<%#Eval("autoAdd") %>' runat="server" />
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </table>
                            <div>
                                <webdiyer:AspNetPager ID="AspNetPager1" NumericButtonType="Text" MoreButtonType="Text"
                                    runat="server" AlwaysShow="False" PageSize="20" InvalidPageIndexErrorMessage="无效页码"
                                    PageIndexOutOfRangeErrorMessage="页码超出范围" ShowCustomInfoSection="Left" CustomInfoHTML=" 每页%PageSize%条记录 | 总共%RecordCount%条记录 "
                                    CustomInfoTextAlign="Left" HorizontalAlign="Right" OnPageChanged="AspNetPager1_PageChanged"
                                    NextPageText="下一页" FirstPageText="首页" LastPageText="末页" PrevPageText="上一页">
                                </webdiyer:AspNetPager>
                            </div>
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </Body>
        </ext:Window>
        <asp:HiddenField runat="server" ID="hdProductSotre" />
    </div>
    </form>

    <script type="text/javascript">
        function selectAll(obj) {
            $(':checkbox', $('#tb_pro')).attr('checked', $(obj).attr('checked') ? true : null);
        }
        // 判断选择的是否存在重复的数据
        function ValidateDuplicate() {
            var msg = '';
            var checkboxes = $(':checkbox[checked]', $('#tb_pro'));
            if ($G('category').length != 0) {
            } else {
            }
            if (checkboxes.length != 0) {
                $(checkboxes).each(function(entryIndex, entry) {
                    var productId = $(entry).parent().attr('ProductId');
                    if (isExistsProduct(productId)) {
                        msg += $(entry).parent().attr('ProductName') + '\r\n';
                    }
                });
                if (msg.length != 0) {
                    return confirm('您当前选择的商品有重复项：\r\n' + msg + '是否忽略重复项继续添加，还是取消添加?');
                }
            } else {
                alert('未选择任何商品！');
                return false;
            }
        }
        function isExistsProduct(productId) {
            var isExists = false;
            var current = $('#hdProductSotre').val();
            if (current.length != 0) {

                var jsonArray = jsonParse(current);
                for (var i = 0; i < jsonArray.length; i++) {
                    if (jsonArray[i]["ProductId"] == productId) {
                        isExists = true;
                        break;
                    }
                }
            }
            return isExists;
        }

        function formatFloat(src, pos) {
            return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
        }

        function calc(obj) {
            var $price = $($(obj).parent().next().find('input')[0]);
            var avgSellerPrice = $(obj).parent().prev().text();

            if (/^\d{1}(\.\d{1,2})?$/.test($(obj).val())) {
                var autoAdd = $(obj).val();
                var price = (parseFloat(autoAdd) + 1) * parseFloat(avgSellerPrice);
                $($price).val(formatFloat(price, 2));
            } else {
                var initAutoAdd = $(obj).next().val();
                var price = (parseFloat(initAutoAdd) + 1) * parseFloat(avgSellerPrice);
                $($price).val(formatFloat(price, 2));
            }
        }
    </script>

</body>
</html>
